package com.scaupos.mis11c.Controller;

import com.scaupos.mis11c.Entities.Orders;
import com.scaupos.mis11c.Repository.OrdersRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

@RestController
public class OrdersController {
    @Autowired
    OrdersRepository ordersRepository;


    @PostMapping(path = "saveOrders")
    @ResponseBody
    public Orders saveOrders(@RequestBody Orders orders) {
        if (orders != null) {
            ordersRepository.save(orders);
            return orders;
        }
        return null;
    }

    @RequestMapping("/allorders")
    @ResponseBody
    public List<Orders> allorders(){
        return ordersRepository.findAll();
    }

    @RequestMapping("/deleteorders")
    public boolean deleteorders(@RequestParam(value="id")Integer id){
        if(ordersRepository.findById(id).get()!=null){
             ordersRepository.deleteById(id);
             return true;
        }
        return false;
    }
}
